/**
 * 
 */
package com.googlecode.pcapj.bridj;

import org.bridj.Pointer;
import org.bridj.StructObject;
import org.bridj.ann.Field;

/**
	Data Fields<br/> 
	<br/>
	pcap_if *  next <br/>
	  if not NULL, a pointer to the next element in the list; NULL for the last element of the list<br/> 
	<br/>
	 <br/>
	char *  name<br/> 
	  a pointer to a string giving a name for the device to pass to pcap_open_live()<br/> 
	<br/>
	 <br/>
	char *  description<br/> 
	  if not NULL, a pointer to a string giving a human-readable description of the device<br/> 
	<br/>
	 <br/>
	pcap_addr *  addresses<br/> 
	  a pointer to the first element of a list of addresses for the interface<br/> 
	<br/>
	 <br/>
	u_int  flags<br/> 
	  PCAP_IF_ interface flags. Currently the only possible flag is PCAP_IF_LOOPBACK, that is set if the interface is a loopback interface.<br/>  
 */
public class pcap_if extends StructObject {
    public pcap_if() { super(); }
    public pcap_if(Pointer<? extends StructObject> pointer) { super(pointer); }

    /**
     * pcap_if *  next <br/>
     * if not NULL, a pointer to the next element in the list; NULL for the last element of the list
     * @return
     */
    @Field(0) 
    public Pointer<pcap_if> next() {
            return this.io.getPointerField(this, 0);
    }
    /**
     * pcap_if *  next <br/>
     * if not NULL, a pointer to the next element in the list; NULL for the last element of the list
     * @param next
     * @return
     */
    @Field(0) 
    public pcap_if next(Pointer<pcap_if> next) {
            this.io.setPointerField(this, 0, next);
            return this;
    }
    /**
     * char *  name<br/>
     * a pointer to a string giving a name for the device to pass to pcap_open_live()<br/>
     * @return
     */
    @Field(1) 
    public Pointer<Byte> name() {
            return this.io.getPointerField(this, 1);
    }
    /**
     * char *  name<br/>
     * a pointer to a string giving a name for the device to pass to pcap_open_live()<br/>
     * @param name
     * @return
     */
    @Field(1) 
    public pcap_if name(Pointer<Byte> name) {
            this.io.setPointerField(this, 1, name);
            return this;
    }
    /**
     * char *  description<br/> 
     * if not NULL, a pointer to a string giving a human-readable description of the device<br/>
     * @return
     */
    @Field(2) 
    public Pointer<Byte> description() {
            return this.io.getPointerField(this, 2);
    }
    /**
     * char *  description<br/> 
     * if not NULL, a pointer to a string giving a human-readable description of the device<br/>
     * @param name
     * @return
     */
    @Field(2) 
    public pcap_if description(Pointer<Byte> description) {
            this.io.setPointerField(this, 2, description);
            return this;
    }
    /**
     * pcap_addr *  addresses<br/>
     * a pointer to the first element of a list of addresses for the interface<br/>
     * @return
     */
    @Field(3) 
    public Pointer<pcap_addr> addresses() {
            return this.io.getPointerField(this, 3);
    }
    /**
     * pcap_addr *  addresses<br/>
     * a pointer to the first element of a list of addresses for the interface<br/>
     * @param addresses
     * @return
     */
    @Field(3) 
    public pcap_if addresses(Pointer<pcap_addr> addresses) {
            this.io.setPointerField(this, 3, addresses);
            return this;
    }
    /**
     * u_int  flags<br/> 
     * PCAP_IF_ interface flags. Currently the only possible flag is PCAP_IF_LOOPBACK, that is set if the interface is a loopback interface.<br/>
     * @return
     */
    @Field(4) 
    public int flags() {
            return this.io.getIntField(this, 4);
    }
    /**
     * u_int  flags<br/>
     * PCAP_IF_ interface flags. Currently the only possible flag is PCAP_IF_LOOPBACK, that is set if the interface is a loopback interface.<br/>
     * @param name
     * @return
     */
    @Field(4) 
    public pcap_if flags(int flags) {
            this.io.setIntField(this, 4, flags);
            return this;
    }
    public int getNetmask(){
    	int netmask = 0xffffff;
    	if(addresses() != Pointer.NULL){
    		pcap_addr pcap_addr = addresses().get();
    		Pointer<sockaddr> socketaddr = pcap_addr.netmask();
    		sockaddr_in socketaddr_in = socketaddr.as(sockaddr_in.class).get();
    		netmask = socketaddr_in.sin_addr().s_addrToint();
    	}
    	return netmask;
//        if(d->addresses != NULL)
//            /* Retrieve the mask of the first address of the interface */
//            netmask=((struct sockaddr_in *)(d->addresses->netmask))->sin_addr.S_un.S_addr;
//        else
//            /* If the interface is without addresses we suppose to be in a C class network */
//            netmask=0xffffff; 
    }
}
